﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Seminor
{
    using Microsoft.Research.Kinect;
    using Microsoft.Research.Kinect.Nui;
    using Microsoft.Research.Kinect.Audio;

    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        private Runtime runtime;
        public MainWindow()
        {
            InitializeComponent();

            Device device = new Device();
            int count= device.Count;
            runtime = new Runtime();
            runtime.Initialize(
                RuntimeOptions.UseColor |
                RuntimeOptions.UseDepth |
                RuntimeOptions.UseDepthAndPlayerIndex |
                RuntimeOptions.UseSkeletalTracking
                );

            // Video StreamのOpen
            runtime.VideoStream.Open(
                ImageStreamType.Video, 2,
                ImageResolution.Resolution640x480, ImageType.Color);
            // Video Frameのハンドラ登録
            runtime.VideoFrameReady +=
                new EventHandler<ImageFrameReadyEventArgs>
                    (runtime_VideoFrameReady);

            runtime.SkeletonFrameReady +=
                new EventHandler<SkeletonFrameReadyEventArgs>
                    (runtime_SkeletonFrameReady);

            // Depth StreamのOpen
            runtime.DepthStream.Open(
                ImageStreamType.Depth, 2,
                ImageResolution.Resolution320x240,
                ImageType.DepthAndPlayerIndex);

            // Depth Frameのハンドラ登録
            runtime.DepthFrameReady +=
                new EventHandler<ImageFrameReadyEventArgs>
                    (runtime_DepthFrameReady);

            

        }

        void runtime_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
        {
            byte[] depthImage = e.ImageFrame.Image.Bits;
            throw new NotImplementedException();
        }

        void runtime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            throw new NotImplementedException();
        }

        void runtime_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
        {
            PlanarImage image = e.ImageFrame.Image;
            videoFrameImage.Source = BitmapImage.Create(
                image.Width, image.Height, 96, 96,
                PixelFormats.Bgr32, null,
                image.Bits,
                image.Width * image.BytesPerPixel);
        }
    }
}
